<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>销毁对象</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .btn {
            position: absolute;
            top: 20px;
            left: 20px;
            z-index: 999;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <button class="btn" onclick="destroyAlarm()">销毁报警对象</button>

    <script>
        /** ---------------------------------地球创建------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            "domid": document.getElementById("app")
        })
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                viewer.flyIn([116.40652135457904, 39.895916046805326, 943.015822904817], [346.3720690214717, -42.33771356206233, 0.0014172887026429263], 3)
            }
        })
        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });


        /**-------------------根据类名（ClassStr）创建一个Alarm对象-----------------------**/
        let sceneObject = objm.createSceneObjectFromJson({
            "id": "ce78c182-a45c-4f2a-963a-0691c0349058",
            "type": "ESAlarm",
            "position": [
                116.404,
                39.904,
                0
            ],
            "name": "ESAlarm_9058",
            "collision": false,
            "allowPicking": true,
            "radius": 200
        })

        /**---------------------销毁场景对象destroySceneObjet----------------------------**/

        function destroyAlarm() {
            if (sceneObject) {
                objm.destroySceneObject(sceneObject)
                sceneObject = undefined// 尽量销毁之后置为undefined
            } else {
                alert("对象已经销毁，请不要连续点击啦！")
            }
        }
    </script>



    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>